package com.pur.zsms.querycode.web;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.pur.zsms.common.exception.GenericException;
import com.pur.zsms.common.support.PageController;
import com.pur.zsms.common.support.PaginationSupport;
import com.pur.zsms.pmsnmanage.role.service.IRoleService;
import com.pur.zsms.pmsnmanage.role.vo.RoleVo;
import com.pur.zsms.pmsnmanage.user.po.UserPo;
import com.pur.zsms.pmsnmanage.user.service.IUserService;
import com.pur.zsms.pmsnmanage.user.vo.UserVo;
import com.pur.zsms.querycode.service.IQueryCodeService;
import com.pur.zsms.systemsetting.datadictionary.po.Code;
import com.pur.zsms.systemsetting.datadictionary.vo.CodeVo;

@Controller
@RequestMapping(value = "/querycode")
public class QueryCodeControllor {
	
	@SuppressWarnings("unused")
	private static final Logger log = LoggerFactory.getLogger(QueryCodeControllor.class);
	
  
	
 	@Resource(name="queryCodeService")
	private IQueryCodeService queryCodeService;
	
	 
	 /*
	  * mode=query代表查询,mode=add代表添加
	  */
	@RequestMapping(value = "/listcode.do", method={RequestMethod.GET})
	public ModelAndView listCode(String codeTypeId,String mode){
	    JSONArray jarr = new JSONArray();
   		List<Code> codeList = null;
  		try {
 			codeList = queryCodeService.listCodeByCodeTypeId(codeTypeId);
  		} catch (Exception e) {
  			log.error("查询失败", e);
 		}
  		if(codeList != null && codeList.size() > 0){
  			if(StringUtils.isNotBlank(mode) && mode.trim().equals("query")){
  				JSONObject json = new JSONObject();
  	            json.put("codeId", "");
  	            json.put("codeName", "全部");
  	            jarr.add(json);
  			}else if(StringUtils.isNotBlank(mode) && mode.trim().equals("add")){
  				JSONObject json = new JSONObject();
  	            json.put("codeId", "");
  	            json.put("codeName", "请选择");
  	            jarr.add(json);
  			}
  			for(int i = 0; i < codeList.size(); i++){
  	  			Code code = codeList.get(i);
  	  			JSONObject json = new JSONObject();
  	            json.put("codeId", code.getCodeId());
  	            json.put("codeName", code.getCodeName());
  	            jarr.add(json);
  	  		}
  		}
  		Map map = new HashMap();
  		map.put("result", jarr.toString()); 
		return new ModelAndView("/systemsetting/queryCode/code", map);
  	}
	

	 
}
